<?php
/**
 * Created by 荣耀电竞.
 * User: 林子彦 <278805354@qq.com>
 * Date: 2018/7/10 0010
 * Time: 17:10
 */
namespace App\Content\Controllers\Admin;

use App\Base\Controllers\Controller;
use App\Content\Contracts\ArticleClassInterface;
use Illuminate\Http\Request;

class ArticleClassController extends Controller
{
    /**
     * @return ArticleClassInterface
     */
      public function getArticleClassInterface(){
          return app()->make(ArticleClassInterface::class);
      }

    /**
     * 新闻列表首页
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     */
      public function index(){

          $menuList=$this->getArticleClassInterface()->getClassMenuList([]);
          $menuArr=array();
          foreach ( $menuList as $k=> $item) {
              $menuArr[$k]["id"]=$item->id;
              $menuArr[$k]["name"]=$item->name;
              $menuArr[$k]["pId"]=$item->pid;
          }
          return view("content.article_class.index")->with("menu_list",json_encode($menuArr));
      }

    /**
     * 获取用户信息
     * @param Request $request
     * @return mixed
     */
      public function edit(Request $request){
          return $this->getArticleClassInterface()->getInfo($request->all());
      }

    /**
     * 选择菜单
     * @param Request $request
     */
    public function classSelectMenus(Request $request){

        $menuList=$this->getArticleClassInterface()->getClassMenuList([]);
        $menuArr=array();
        foreach ( $menuList as $k=> $item) {
            $menuArr[$k]["id"]=$item->id;
            $menuArr[$k]["name"]=$item->name;
            $menuArr[$k]["pId"]=$item->pid;
        }
        return view("admin.config.show_select_menus")->with("menu_list",json_encode($menuArr));
    }

    public function del(Request $request){
          return $this->getArticleClassInterface()->delData($request->all());
    }

    /**
     * 保存数据
     * @param Request $request
     * @return mixed
     */
    public function save(Request $request){
      return   $this->getArticleClassInterface()->updateOrCreateClassClassData($request->all());
    }


}